home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / dialog / fcombo.c < prev    next >
C/C++ Source or Header  |  1996-08-01  |  2KB  |  106 lines

  1. #pragma implementation
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include "../misc/misc.h"
  6. #include "dialog.h"
  7. #include "fcombo.h"
  8.  
  9. PUBLIC ELM_STR::ELM_STR(const char *_value, const char *_verbose)
  10. {
  11.     value = strdup(_value);
  12.     verbose = strdup(_verbose);
  13. }
  14.  
  15. PUBLIC ELM_STR::~ELM_STR()
  16. {
  17.     free (value);
  18.     free (verbose);
  19. }
  20.  
  21. PUBLIC ELM_STR *LIST_STR::getitem(int no)
  22. {
  23.     return (ELM_STR*)ARRAY::getitem(no);
  24. }
  25. /*
  26.     The FIELD_COMBO class is a string editor with an assist
  27.     hot key. When triggered a list of string is displayed
  28.     and the user is allowed to pick a value from there.
  29.     The value (if selected) will replace the input buffer.
  30. */
  31. PUBLIC FIELD_COMBO::FIELD_COMBO(
  32.     const char *_prompt,
  33.     SSTRING &_str)
  34.     : FIELD_STRING_HELP (_prompt,_str)
  35. {
  36.     opts = new LIST_STR;
  37. }
  38.  
  39. PUBLIC FIELD_COMBO::~FIELD_COMBO()
  40. {
  41.     delete opts;
  42. }
  43.  
  44. /*
  45.     Add one string option to the combo box pick list
  46. */
  47. PUBLIC void FIELD_COMBO::addopt(const char *str)
  48. {
  49.     opts->add (new ELM_STR(" ",str));
  50. }
  51. /*
  52.     Add one string option to the combo box pick list.
  53.     This time there is two string. The strings will be show in
  54.     the pick list like this
  55.  
  56.     value verbose
  57. */
  58. PUBLIC void FIELD_COMBO::addopt(const char *value, const char *verbose)
  59. {
  60.     opts->add (new ELM_STR(value,verbose));
  61. }
  62. PROTECTED void FIELD_COMBO::assist(WINDOW *dialog)
  63. {
  64.     int nbopt = opts->getnb();
  65.     char **tbopt = (char**)malloc_err(nbopt*2*sizeof(char*));
  66.     for (int i=0,ii=0; i<nbopt; i++){
  67.         ELM_STR *elm = opts->getitem(i);
  68.         tbopt[ii++] = elm->value;
  69.         tbopt[ii++] = elm->verbose;
  70.     }
  71.     int sel = 0;
  72.     MENU_STATUS ret = dialog_menu ("Help list"
  73.         ,"Pick one value"
  74.         ,NULL
  75.         ,0
  76.         ,nbopt,tbopt,sel);
  77.     free (tbopt);
  78.     touchwin(stdscr);
  79.     touchwin(dialog);
  80.     if (ret == MENU_OK){
  81.         ELM_STR *elm = opts->getitem(sel);
  82.         if (strcmp(elm->value," ")==0){
  83.             strcpy (buf,elm->verbose);
  84.         }else{
  85.             strcpy (buf,elm->value);
  86.         }
  87.         draw(dialog);
  88.     }
  89. }
  90.  
  91. /*
  92.     Add a combo field to the dialog.
  93.     The object will be destroyed by the dialog itself.
  94.     The object is returned so the caller may add options in the
  95.     pick list.
  96. */
  97. PUBLIC FIELD_COMBO *DIALOG::newf_combo(
  98.     const char *prompt,
  99.     SSTRING &str)
  100. {
  101.     FIELD_COMBO *s = new FIELD_COMBO(prompt,str);
  102.     add (s);
  103.     return s;
  104. }
  105.  
  106.